package demo01;

class Phone {
    public synchronized void sendEmail() throws Exception {
        System.out.println("---send Email---");
    }

    public synchronized void sendSMS() throws Exception {
        System.out.println("---send SMS---");
    }
}

/**
 * 8 lock
 * 1 标志访问，请问先打印邮件还是短信？不一定
 */
public class Lock8Demo05 {
    public static void main(String[] args) throws InterruptedException{
        Phone phone = new Phone();
        new Thread(() -> {
            try {
                phone.sendEmail();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }, "A").start();

        new Thread(() -> {
            try {
                phone.sendSMS();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }, "B").start();
    }
}
